package com.dy.system.service.impl;

import java.util.List;
import java.util.Map;

import com.dy.system.domain.MedicalEquipmentReportLog;
import com.dy.system.mapper.MedicalEquipmentReportLogMapper;
import com.dy.system.service.IMedicalEquipmentReportLogService;
import org.apache.commons.collections4.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * 设备上报日志Service业务层处理
 *
 * @author ruoyi
 * @date 2022-08-15
 */
@Service
public class MedicalEquipmentReportLogServiceImpl implements IMedicalEquipmentReportLogService {
    @Autowired
    private MedicalEquipmentReportLogMapper medicalEquipmentReportLogMapper;

    /**
     * 查询设备上报日志
     *
     * @param id 设备上报日志主键
     * @return 设备上报日志
     */
    @Override
    public MedicalEquipmentReportLog selectMedicalEquipmentReportLogById(Long id)
    {
        return medicalEquipmentReportLogMapper.selectMedicalEquipmentReportLogById(id);
    }

    /**
     * 查询设备上报日志列表
     *
     * @param medicalEquipmentReportLog 设备上报日志
     * @return 设备上报日志
     */
    @Override
    public List<MedicalEquipmentReportLog> selectMedicalEquipmentReportLogList(MedicalEquipmentReportLog medicalEquipmentReportLog)
    {
        return medicalEquipmentReportLogMapper.selectMedicalEquipmentReportLogList(medicalEquipmentReportLog);
    }

    /**
     * 新增设备上报日志
     *
     * @param medicalEquipmentReportLog 设备上报日志
     * @return 结果
     */
    @Override
    public int insertMedicalEquipmentReportLog(MedicalEquipmentReportLog medicalEquipmentReportLog)
    {
        return medicalEquipmentReportLogMapper.insertMedicalEquipmentReportLog(medicalEquipmentReportLog);
    }

    /**
     * 修改设备上报日志
     *
     * @param medicalEquipmentReportLog 设备上报日志
     * @return 结果
     */
    @Override
    public int updateMedicalEquipmentReportLog(MedicalEquipmentReportLog medicalEquipmentReportLog)
    {
        return medicalEquipmentReportLogMapper.updateMedicalEquipmentReportLog(medicalEquipmentReportLog);
    }

    /**
     * 批量删除设备上报日志
     *
     * @param ids 需要删除的设备上报日志主键
     * @return 结果
     */
    @Override
    public int deleteMedicalEquipmentReportLogByIds(Long[] ids)
    {
        return medicalEquipmentReportLogMapper.deleteMedicalEquipmentReportLogByIds(ids);
    }

    /**
     * 删除设备上报日志信息
     *
     * @param id 设备上报日志主键
     * @return 结果
     */
    @Override
    public int deleteMedicalEquipmentReportLogById(Long id)
    {
        return medicalEquipmentReportLogMapper.deleteMedicalEquipmentReportLogById(id);
    }

    @Override
    public List<MedicalEquipmentReportLog> selectAppletMedicalEquipmentReportList(String code) {
        return medicalEquipmentReportLogMapper.selectAppletMedicalEquipmentReportList(code);
    }

    @Override
    public int getMedicalHandleData(String handleType, Long medicalId, String code) {
        Integer handleData = medicalEquipmentReportLogMapper.getMedicalHandleData(handleType, medicalId, code);
        return handleData == null ? 0 : handleData;
    }

    @Override
    public Integer getMedicalHandleDataByInsIdAndTime(Long institutionId, String time) {
        Map<String,Object> map = medicalEquipmentReportLogMapper.getMedicalHandleDataByInsIdAndTime(institutionId,time);
        Integer sewageL = MapUtils.getInteger(map,"sewageL",0);
        Integer sewageT = MapUtils.getInteger(map,"sewageT",0);
        return sewageL + sewageT*1000;
    }

    @Override
    public Integer getMedicalHandleShengData(String handleType, Long medicalId, String code) {
        Map<String,Object> map  = medicalEquipmentReportLogMapper.getMedicalHandleShengData(handleType, medicalId, code);
        Integer sewageL = MapUtils.getInteger(map,"sewageL",0);
        Integer sewageT = MapUtils.getInteger(map,"sewageT",0);
        return sewageL + sewageT*1000;
    }
}
